/*
 * @Author: wangshuixin 2412658453@qq.com
 * @Date: 2025-06-04 09:20:16
 * @LastEditors: wangshuixin 2412658453@qq.com
 * @LastEditTime: 2025-06-22 16:50:00
 * @FilePath: /my-app/src/utils/ApplyFile.ts
 * @Description: 仲裁申请书 >>> 导出配置文件
 */
import { cmToDxa, ptToDxa, TextRunObjectType } from './WordExporter';

interface ApplyFileType {
  applicant?: string, // 申请人
  gender?: string, // 性别
  nation?: string, // 民族
  birthday?: string, // 出生日期
  identityCard?: string, // 身份证号
  registeredResidence?: string, // （申请人）户籍地
  applicantPhone?: string, // （申请人）联系电话
  applicantAddress?: string, // （申请人）现住址
  respondent?: string, // 被申请人
  creditCode?: string, // 统一社会信用代码
  respondentAddress?: string, // （被申请人）法定住所地
  businessLocation?: string, // （被申请人）实际经营地
  legalRepresentative?: string, // （被申请人）法定代表人（主要负责人）
  respondentPosition?: string, // （被申请人）职务
  respondentPhone?: string, // （被申请人）联系人、电话
  respondent_1?: string, // 第二被申请人（第三人）
  respondentAddress_1?: string, // 第二被申请人（第三人）法定住所地
  businessLocation_1?: string, // 第二被申请人（第三人）实际经营地
  legalRepresentative_1?: string, // 第二被申请人（第三人）法定代表人（主要负责人）
  respondentPosition_1?: string, // 第二被申请人（第三人）职务
  respondentPhone_1?: string, // 第二被申请人（第三人）联系人、电话
  applyReq?: TextRunObjectType[][], // 仲裁请求
  applyReason?: TextRunObjectType[][], // 事实及理由
}

export const applyFileGenerator = async (exporter, config?: ApplyFileType) => {
  const tableData = [
    [
      {
        data: [[
          {
            text: "申请人",
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [[
          {
            text: `${config?.applicant}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 59,
      },
      {
        data: [[
          {
            text: "性 别",
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 26,
      },
      {
        data: [[
          {
            text: `${config?.gender}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 18,
      },
      {
        data: [[
          {
            text: "民 族",
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 18,
      },
      {
        data: [[
          {
            text: `${config?.nation}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 17,
      }
    ],
    [
      {
        data: [
          [{
            text: "出生日期",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [[
          {
            text: `${config?.birthday}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 59,
      },
      {
        data: [[
          {
            text: "身份证号",
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 26,
      },
      {
        data: [[
          {
            text: `${config?.identityCard}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 53,
      },
    ],
    [
      {
        data: [
          [{
            text: "户籍地",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [[
          {
            text: `${config?.registeredResidence}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 59,
      },
      {
        data: [[
          {
            text: "联系电话",
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 26,
      },
      {
        data: [[
          {
            text: `${config?.applicantPhone}`,
            style: { fontSize: 14, font: "仿宋" }
          }
        ]],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 53,
      },
    ],
    [
      {
        data: [
          [{
            text: "现住址",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.applicantAddress}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "被申请人",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.respondent}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "统一社会",
            style: { fontSize: 14, font: "仿宋" }
          }], [{
            text: "信用代码",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.creditCode}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "法定住所地",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.respondentAddress}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "实际经营地",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.businessLocation}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "法定代表人（主要负责人）",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 63,
      },
      {
        data: [
          [{
            text: `${config?.legalRepresentative}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 55,
      },
      {
        data: [
          [{
            text: "职 务",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 18,
      },
      {
        data: [
          [{
            text: `${config?.respondentPosition}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 35,
      },
    ],
    [
      {
        data: [
          [{
            text: "联系人、电话",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.respondentPhone}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
  ]
  const secondRespondent = [
    [
      {
        data: [
          [{
            text: "第二被申请人（第三人）",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 63,
      },
      {
        data: [
          [{
            text: `${config?.respondent_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 108,
      },
    ],
    [
      {
        data: [
          [{
            text: "法定住所地",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.respondentAddress_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "实际经营地",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.businessLocation_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
    [
      {
        data: [
          [{
            text: "法定代表人（主要负责人）",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 63,
      },
      {
        data: [
          [{
            text: `${config?.legalRepresentative_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 55,
      },
      {
        data: [
          [{
            text: "职 务",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 18,
      },
      {
        data: [
          [{
            text: `${config?.respondentPosition_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 35,
      },
    ],
    [
      {
        data: [
          [{
            text: "联系人、电话",
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "center",
        columnSpan: 33,
      },
      {
        data: [
          [{
            text: `${config?.respondentPhone_1}`,
            style: { fontSize: 14, font: "仿宋" }
          }]
        ],
        verticalAlign: "center",
        alignment: "left",
        columnSpan: 138,
      },
    ],
  ]
  // 段落
  const paragraphConfig = {
    spacing: {
      line: ptToDxa(20),
      lineRule: "exact"
    },
    indent: {
      left: cmToDxa(-1),
      right: cmToDxa(-1),
      firstLine: cmToDxa(0.84)
    }
  }
  const arbitrationClaimsTitle = [{
    text: "仲裁请求：",
    style: {
      fontSize: 14,
      font: "黑体",
    }
  }]
  const reasonTitle = [{
    text: "事实及理由：",
    style: {
      fontSize: 14,
      font: "黑体",
    }
  }]
  const titleStrArr = ["仲 裁 申 请 书"]
  exporter.addTitle(titleStrArr)
  exporter.addTable(
    [...tableData, ...secondRespondent],
    {
      height: { value: cmToDxa(1.25), rule: "exact" },
      layout: "fixed",
      columnWidths: Array(171).fill(1000/171),
      indent: { firstLine: cmToDxa(0.8) }
    }
  )
  exporter.addParagraph(
    arbitrationClaimsTitle,
    {
      spacing: {
        line: ptToDxa(23),
        lineRule: "exact"
      },
      indent: {
        left: cmToDxa(-0.1),
      }
    }
  )
  // 仲裁请求
  config?.applyReq?.forEach((arbitrationClaimsRowData: TextRunObjectType[]) => {
    exporter.addParagraph(arbitrationClaimsRowData, paragraphConfig)
  })
  exporter.addParagraph(
    reasonTitle,
    {
      spacing: {
        line: ptToDxa(23),
        lineRule: "exact"
      },
      indent: {
        left: cmToDxa(-0.1),
      }
    }
  )
}
